<template>
  <div class="app-container">
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-row>
        <el-col :span="24">
          <el-form-item label="优惠卷码：">
            <el-input size="mini" v-model="formInline.user" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="状态：">
            <el-select size="mini" v-model="formInline.val" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button size="mini" type="primary" @click="onSubmit">查询</el-button>
            <el-button size="mini" @click="onReset">重置</el-button>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item>
            <el-button size="mini" type="primary" @click="onAdd">作废</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="name" label="优惠卷码">
        <template slot-scope="scope">
          <el-button type="text" @click="gotoDetail(scope.row.id)">北京移动</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="可兑换的截至日期"></el-table-column>
      <el-table-column prop="name" label="兑换后的有效期(天)"></el-table-column>
      <el-table-column prop="name" label="面值(元)"></el-table-column>
      <el-table-column prop="name" label="退卷次数"></el-table-column>
      <el-table-column prop="name" label="状态"></el-table-column>
      <el-table-column prop="name" label="更新时间"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="text" @click="onAdd">作废</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <!-- 分页组件 -->
    </div>
    <el-dialog title="修改" :visible.sync="dialogVisible" width="40%">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-row>
          <el-col :span="24">
            <el-form-item label="渠道商号：">222222222222</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="名称：">
              <el-input v-model="input" placeholder="请输入内容"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人：">
              <el-input v-model="input" placeholder="请输入内容"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否有效：">
              <el-switch v-model="value" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话：">
              <el-input v-model="input" placeholder="请输入内容"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>

        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog :visible.sync="dialogAdd" width="40%">
      <div>
        作废优惠券会导致优惠券立即失效
        <br />共xx张优惠券将被作废，你还要继续吗？
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="dialogAdd = false">取 消</el-button>

        <el-button size="mini" type="primary" @click="onSubmit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    const generateData = _ => {
      const data = []
      for (let i = 1; i <= 15; i++) {
        data.push({
          key: i,
          label: `备选项 ${i}`,
          disabled: i % 4 === 0
        })
      }
      return data
    }
    return {
      data: generateData(),
      arr: [],
      value1: '',
      dialogVisible: false,
      dialogAdd: false,
      value: true,

      options: [
        {
          value: '选项1',
          label: '待审批'
        },
        {
          value: '选项2',
          label: '已审批'
        },
        {
          value: '选项3',
          label: '已下载'
        },
        {
          value: '选项4',
          label: '已兑换'
        },
        {
          value: '选项5',
          label: '已过兑换期'
        },
        {
          value: '选项6',
          label: '已过使用期'
        },
        {
          value: '选项7',
          label: '已作废'
        }
      ],
      input: '',
      formInline: {
        user: '',
        region: '',
        val: ''
      },
      tableData: [
        {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }
      ],
      multipleSelection: []
    }
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    onSubmit() {
      this.$notify({
        title: '成功',
        message: '这是一条成功的提示消息',
        type: 'success'
      })
      this.dialogAdd = false
    },
    onEdit() {
      this.dialogVisible = true
    },
    onAdd() {
      this.dialogAdd = true
    },
    gotoDetail(val) {
      this.$router.push({ path: 'couponDetail' })
    },
    onReset() {
      this.formInline = {
        user: '',
        region: '',
        val1: '',
        val2: ''
      }
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    },
    handleCurrentChange(row, event, column) {
      console.log(row, event, column, event.currentTarget)
    },
    handleEdit(index, row) {
      console.log(index, row)
    },
    handleDelete(index, row) {
      console.log(index, row)
    }
  }
}
</script>

<style scoped>
.line {
  text-align: center;
}
.el-input {
  height: 33px;
  font-size: 13px;
  box-shadow: none;
  border: 1px solid #e9e9e9;
}
</style>

